package com.example.demo.config;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @Question LoginInterceptor
 * @Date 2023/1/4 16:33
 * @Solution
 */
@Component
public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        System.out.println(session.getAttribute("userinfo"));
        if(session!=null && session.getAttribute("userinfo")!=null) {
            response.sendRedirect("/myblog_list.html");
            return true;
        }
        response.sendRedirect("/login.html");
        return false;
    }
}
